<template>
	<!-- 搜索结果 -->
	<view class="contentsss">
		<view class="my-head">
			<u-icon name="arrow-left" color="#666666" size="22" style="margin-right: 20rpx;" @click="fnCancel"></u-icon>
			<u-search :clearabled="true" v-model="keyWord" @clear="fnCancel" :showAction="false"
				@focus="onSearchChange">
			</u-search>

		</view>


		<scroll-view v-if="shouyeDataList.length==0 || qiyeDataList.length==0" scroll-y
			:style="{'height':windowHeight-50-statusBarH+'px'}" :refresher-threshold="20" @scrolltolower="ReachBottom"
			:lower-threshold='80' refresher-enabled="true" :refresher-triggered="triggered"
			@refresherrefresh="onRefresh" @refresherrestore="onRestore" refresher-default-style="none" class="scroll">
			<u-loading-icon :show="triggered" text="正在刷新" style="padding-top: 10rpx;"></u-loading-icon>
			<template>
				<view style="padding: 0 20rpx;" v-if="zhiweiqiyeId==1 && shouyeDataList.length > 0">
					<view class="content3" @click="zhiwei(item)" v-for="(item,index) in shouyeDataList">
						<view class="fl-lr-c">
							<view class="job_name">
								{{item.JobName}}
							</view>
							<view class="wages" v-if="item.Negotiable">
								面议
							</view>
							<view class="wages" v-else-if=" item.MaxWage<=3000">
								{{item.MaxWage/1000}}K以下
							</view>
							<view class="wages" v-else>
								{{item.MinWage>=1000?item.MinWage/1000:item.MinWage}}K-{{item.MaxWage>=1000?item.MaxWage/1000:item.MaxWage}}K
							</view>
						</view>
						<view class="requirement  fl-t">
							<view class="view">{{item.EducationDesc}}</view>
							<view class="xian"></view>
							<view class="view" v-if="item.Graduate">应届生</view>
							<view class="view" v-else-if="item.Student">在校生</view>
							<view class="view" v-else>{{item.MinExperience}}~{{item.MaxExperience}}年经验</view>
							<view class="xian"></view>
							<view class="view" v-if="item.WorkType==0">全职</view>
							<view class="view" v-else-if="item.WorkType==1">兼职</view>
							<view class="view" v-else>实习</view>
							<view class="xian"></view>
							<view class="view">招{{item.Amount}}人</view>
						</view>
						<view class="treatment">
							<view v-for="(item,index) in fuliDataList[index]" v-if="index<4">
								{{item}}
							</view>
							<view v-if="item.Corp.RestTimeDesc">{{item.Corp.RestTimeDesc}}</view>
						</view>
						<view class="company-bottom fl-lr-c">
							<view class="left-company  fl-t">
								<view class="logobox">
									<image class="logo" :src="imgStr(item)" mode=""></image>
								</view>

								<view class="fl-t company-name-box">
									<view class="on-line"
										v-if="item.UserOnlineInfo !== null && item.UserOnlineInfo.State == true"></view>
									<view class="on-line1" v-else></view>
									<view class="company-name">{{item.CorpName}}</view>
								</view>
							</view>
							<view class="position_item1  fl-t">
								<view>{{item.PcaAddress}}</view>

							</view>
						</view>
					</view>
				</view>
				<u-empty v-else mode="data" icon="/static/recruit/index/qsy.png" :width="windowWidth" marginTop="150">
				</u-empty>
			</template>
			<template>
				<view v-if='qiyeDataList.length > 0' class="content4" v-for="(item,index) in qiyeDataList"
					@click="qiye(item)">
					<view class="content-text">
						<view class="con-img">
							<image class="logo" :src="imgStr1(item)"></image>
						</view>
						<view class="con-right">
							<view class="con-title">
								{{item.FullName}}
							</view>
							<view class="con-text">
								<view class="con-text-view" v-if="item.IndustryDesc">{{item.IndustryDesc}}</view>
								<view class="xian" v-if="item.IndustryDesc"></view>
								<view class="con-text-view" v-if="item.CategoryDesc">{{item.CategoryDesc}}</view>
								<view class="xian" v-if="item.CategoryDesc"></view>
								<view class="con-text-view" v-if="item.SizeDesc">{{item.SizeDesc}}人</view>
							</view>
							<view class="con-zw">
								<view>{{item.HotJob.length}}</view>个热招职位
							</view>

						</view>
					</view>
				</view>
				<u-empty v-else mode="data" icon="/static/recruit/index/qsy.png" :width="windowWidth"
					marginTop="150"></u-empty>
			</template>
			<u-loadmore :status="status" v-if="!shouyeDataList.length==0" />
		</scroll-view>




	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyWord: "",
				shouyeDataList: [], //职位存储数据
				qiyeDataList: [], //企业存储数据
				pageindex: 1,
				pagesize: 10,
				PositionId: null,
				URL: this.$config.domain.staticUrl,
				boxHeight: wx.getSystemInfoSync().windowHeight - 48 - 37, //获取当前屏幕高度
				status: 'loadmore',

				flag: true,
				zhiweiqiyeId: null,
				statusBarH: '',
				windowHeight: '',
				windowWidth: '',
				triggered: false,
			}
		},
		onLoad(option) {
			// console.log(option);
			if (option) {
				this.keyWord = option.keyword
				this.zhiweiqiyeId = option.jobCorp
			}

		},

		onShow() {

		},
		created() {
			if (this.zhiweiqiyeId == 1) {
				this.searchData()
			} else {
				this.qiyeData()
			}
			const app = getApp()
			this.statusBarH = app.globalData.statusBarH //状态栏高度
			this.windowHeight = app.globalData.phoneInformation.windowHeight //屏幕高度
			this.windowWidth = app.globalData.phoneInformation.windowWidth

		},
		methods: {
			ReachBottom() {
				// 加载前值为loadmore，加载中为loading，没有数据为nomore
				console.log("触底加载");
				if (this.zhiweiqiyeId == 1) {
					if (this.status != "nomore") {
						this.status = "loading";
						this.searchData();
					}

				} else {
					if (this.status != "nomore") {
						this.status = "loading";
						this.qiyeData();
					}
				}



			},
			// 下拉刷新
			onRefresh() {
				this.triggered = true;
				setTimeout(() => {
					this.triggered = false;
					if (this.tab == 0) {
						if (this.status != "nomore") {
							this.status = "loading";

							this.search();

						}
					} else {
						if (this.status != "nomore") {
							this.status = "loading";
							this.qiyeData();
						}
					}

				}, 2000)
			},
			// 下拉复位
			onRestore() {
				this.triggered = false; // 需要重置
			},
			// 显示头像
			imgStr(item) {
				if (item.Corp && item.Corp.LogoPath) {
					return this.URL + item.Corp.LogoPath
				} else {
					return '/static/static/images/default-corp-logo.png'
				}
			},
			imgStr1(item) {
				if (item && item.LogoPath) {
					return this.URL + item.LogoPath
				} else {
					return this.URL + '/upfile/c/10000/387135495057541.jpeg'
				}
			},
			searchChange() {

			},
			search(e) {
				// console.log(e);
				this.keyWord = e
				this.shouyeDataList = []
				this.pageindex = 1
				this.pagesize = 10

				this.searchData()
			},
			searchData() {
				let obj = {
					PageIndex: this.pageindex,
					PageSize: this.pagesize,
					KeyWord: this.keyWord, //关键字

				}
				// console.log(obj);
				this.$http.huirc.jobsearch(obj).then(res => {
					// console.log(res);
					if (res.Result) {
						// console.log(res.Result)
						if (res.Result.Items.length == 0) {
							// 没有数据----
							this.status = "nomore";
							return;
						}
						this.shouyeDataList = this.shouyeDataList.concat(res.Result.Items);
						let arr = []
						this.shouyeDataList.forEach(item => {
							arr.push(JSON.parse(item.Corp.Welfares))
						})
						this.fuliDataList = arr
						// console.log(res.Result.Items.length, this.pagesize)

						if (res.Result.Items.length >= this.pagesize) {
							// 表示还有数据

							this.pageindex++;
						} else {
							this.status = "nomore"
						}

					}
				})

			},
			// 企业查询
			qiyeData() {
				let obj = {
					PageIndex: this.pageindex,
					PageSize: this.pagesize,
					KeyWord: this.keyWord, //关键字
				}
				// console.log(obj);
				this.$http.huirc.corpsearch(obj).then(res => {
					// console.log(res);
					if (res.Result) {
						// console.log(res.Result)
						if (res.Result.Items.length == 0) {
							// 没有数据----
							this.status = "nomore";
							return;
						}
						this.qiyeDataList = this.qiyeDataList.concat(res.Result.Items);


						// console.log(res.Result.Items.length, this.pagesize)

						if (res.Result.Items.length >= this.pagesize) {
							// 表示还有数据

							this.pageindex++;
						} else {
							this.status = "nomore"
						}

						// console.log(this.qiyeDataList);
					}


				})
			},


			fnCancel() {
				uni.navigateBack();
			},
			onSearchChange(e) {
				// console.log(e);
				this.fnCancel()
			},
			// 跳转企业
			qiye(item) {
				// console.log(item);
				let corpId = item.Id
				uni.navigateTo({
					url: "/pages/views/packageA/type-jobhunting/search/companyDetails?corpId=" + corpId
				})
			},
			//跳转职位详情
			zhiwei(item) {
				// console.log(item);
				let id = item.Id
				uni.navigateTo({
					url: `/pages/views/packageA/type-jobhunting/search/JobDetails?id=` + id
				})
			}
		},
	}
</script>


<style lang="scss" scoped>
	.contentsss {
		.scroll {
			// border: 1rpx solid red;
			box-sizing: border-box;
			margin-top: calc(88rpx + var(--status-bar-height));
			z-index: 888;
		}
	}

	.occupy {
		height: calc(88rpx + var(--status-bar-height));
	}

	.my-head {
		position: fixed;
		top: 0;
		width: 100%;
		padding: var(--status-bar-height) 30rpx 0 30rpx;
		height: calc(88rpx + var(--status-bar-height));
		display: flex;
		//justify-content: space-between;  
		align-items: center;
		box-sizing: border-box;
		z-index: 999;
		background-color: #fff;

		.head-right {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
			min-width: 70rpx;
			margin-left: 20rpx;
		}
	}



	.content3 {
		width: 100%;
		margin-top: 20rpx;
		background-color: #fff;
		padding: 40rpx 30rpx 20rpx;
		box-sizing: border-box;
		border-radius: 8rpx;
		z-index: 880;

		view {

			.job_name {
				width: auto;
				font-size: 36rpx;
				font-weight: bold;
				color: #000000;
			}

			.wages {
				font-size: 34rpx;
				font-weight: 400;
				color: #F35370;
			}
		}

		.requirement {
			width: 100%;
			margin: 30rpx 0 20rpx;

			.view {
				font-size: 26rpx;
				font-weight: 400;
				color: #666666;
				margin-right: 20rpx;
			}

			.xian {
				width: 0rpx;
				height: 16rpx;
				opacity: 0.2;
				border: 1rpx solid #707070;
				margin-right: 20rpx;
			}
		}

		.treatment {
			// border-bottom: 1px solid #DEE5EF;
			display: flex;
			/* flex-wrap: wrap; */
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			width: 98%;

			view {
				padding: 8rpx 16rpx;
				background: #F7F7F7;
				border-radius: 4rpx;
				margin-right: 20rpx;
				width: auto;
				margin-bottom: 20rpx;

				background: #F7F8FA;
				border-radius: 4rpx;
				opacity: 1;

				font-size: 24rpx;
				font-weight: 400;
				color: #666666;
			}
		}

		.company-bottom {
			padding-top: 24rpx;

			.left-company {
				width: auto;
				height: auto;

				.logobox {
					width: 42rpx;
					height: 42rpx;
					background: #FFFFFF;
					border-radius: 8rpx;
					opacity: 1;
					border: 1rpx solid rgba(112, 112, 112, 0.2);
					display: flex;
					justify-content: center;
					align-items: center;

					.logo {
						width: 31rpx;
						height: 31rpx;
						flex-shrink: 0;
					}
				}


				.company-name-box {
					height: 60rpx;
					margin-left: 20rpx;
					position: relative;

					.on-line {
						position: absolute;
						width: 12rpx;
						height: 12rpx;
						background: #14C88B;
						border-radius: 50%;
						bottom: 6rpx;
						left: -30rpx;
					}

					.on-line1 {
						position: absolute;
						width: 12rpx;
						height: 12rpx;
						background: #b2b6bf;
						border-radius: 50%;
						bottom: 6rpx;
						left: -30rpx;
					}

					.company-name {
						font-size: 26rpx;
						font-weight: 500;
						color: #272636;
					}
				}
			}

			.position_item1 {
				font-size: 24rpx;
				font-weight: 400;
				color: #999999;


				view {
					margin-left: 20rpx;
				}
			}
		}
	}

	.content4 {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 30rpx;
		box-sizing: border-box;

		.content-text {
			display: flex;
			// align-items: center;

			.con-img {
				width: 98rpx;
				height: 98rpx;
				background: #FFFFFF;
				border-radius: 10rpx;
				opacity: 1;
				border: 1rpx solid rgba(112, 112, 112, 0.2);
				display: flex;
				justify-content: center;
				align-items: center;

				.logo {
					width: 70rpx;
					height: 70rpx;
					flex-shrink: 0;
				}

			}

			.con-right {
				margin-left: 20rpx;

				.con-title {
					font-size: 36rpx;
					font-weight: bold;
					color: #000000;

				}

				.con-text {
					display: flex;
					margin: 15rpx 0 30rpx;
					align-items: center;

					.con-text-view {
						font-size: 26rpx;
						font-weight: 400;
						color: #666666;

					}

					.xian {
						width: 0rpx;
						height: 16rpx;
						opacity: 0.2;
						border: 1rpx solid #707070;
						margin: 0 18rpx;
					}
				}

				.con-zw {
					// width: 200rpx;
					display: flex;
					margin: 20rpx 0 10rpx;
					background-color: #F7F7F7;
					padding: 10rpx;
					// text-align: center;
					width: fit-content;
					font-size: 24rpx;
					;

					view {
						// padding: 14rpx 20rpx;
						font-size: 24rpx;
						font-family: PingFang-SC-Heavy;
						// font-weight: 500;
						color: #F35370;

					}
				}
			}

		}
	}

	.queshenye {
		height: calc(100vh - 88rpx + var(--status-bar-height));
		background-color: #fff;
		text-align: center;

		.queshenye-chi {
			height: 500px;
		}
	}
</style>